home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
pcr
/
pcr4_4.lha
/
DIST
/
boot
/
CommandLoopCompatibility.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-05-04
|
5KB
|
204 lines
/* begincopyright
Copyright (c) 1988 Xerox Corporation. All rights reserved.
Use and copying of this software and preparation of derivative works based
upon this software are permitted. Any distribution of this software or
derivative works must comply with all applicable United States export
control laws. This software is made available AS IS, and Xerox Corporation
makes no warranty about the software, its performance or its conformity to
any specification. Any person obtaining a copy of this software is requested
to send their name and post office or electronic mail address to
PCRCoordinator.pa@xerox.com, or to:
PCR Coordinator
Xerox PARC
3333 Coyote Hill Rd.
Palo Alto, CA 94304
endcopyright */
/*
* CommandLoopCompatibility.c
*
* Simulation of old command interface. OBSOLESCENT and DISCOURAGED.
*
* Demers, April 10, 1990 8:10:54 am PDT
*
*/
#include <xr/ThreadsMsg.h>
#include <xr/CommandLine.h>
#include <xr/CommandLinePrivate.h>
#include <xr/CommandLoop.h>
static char *XR_currentCommand = NIL;
void
XR_SetCurrentCommand(s)
char *s;
{
char *buf;
if( s == NIL ) { XR_currentCommand = NIL; return; }
buf = (char *) XR_malloc( 1+strlen(s) );
(void) strcpy(buf, s);
XR_currentCommand = buf;
}
char *
XR_GetCurrentCommand()
{
return XR_currentCommand;
}
typedef struct XR_CLOldRegistrationRep {
CommandProc clor_commandProc;
XR_Pointer clor_clientData;
} * XR_CLOldRegistration;
static
XR_CLPROC(XR_CLProc_invokeOldStyleCommandProc)
{
XR_CLHandleInner clh = ((XR_CLHandleInner)(clce->clce_h));
XR_CLOldRegistration clor = ((XR_CLOldRegistration)(self->mp_x));
int len, i;
char *buf;
char *pfrom, *pto;
len = 1;
for( i = 0; i < argc; i++ ) len += (1+strlen(argv[i]));
buf = (char *) XR_malloc(len);
if( buf == NIL ) {
XR_CLErrorMsg "%s: out of memory\n", argv[0]);
return (-1);
}
pto = buf;
for( i = 0; i < argc; i++ ) {
pfrom = argv[i];
while( (*pto++ = *pfrom++) != 0 ) ;
pto[-1] = ' ';
}
pto[0] = 0;
XR_SetCurrentCommand(buf);
(**(clor->clor_commandProc))(buf, clor->clor_clientData,
clor->clor_commandProc);
return 1;
}
void
XR_register(key, proc, doc, clientData)
char *key;
CommandProc proc;
char *doc;
XR_Pointer clientData;
{
XR_CLOldRegistration clor;
XR_MesaProc mp;
XR_CLRegistration r;
clor = (XR_CLOldRegistration) XR_malloc(sizeof (*clor));
if( clor == NIL ) XR_Panic("XR_register 0 out of memory");
clor->clor_commandProc = proc;
clor->clor_clientData = clientData;
mp = XR_MakeMesaProc(
((XR_UntypedProc)(XR_CLProc_invokeOldStyleCommandProc)),
((XR_Pointer)(clor)) );
if( mp == NIL ) XR_Panic("XR_register 1 out of memory");
r = XR_CLRegisterProc( XR_globalCLProcsHandle, key, FALSE, doc, mp, TRUE );
if( r == NIL ) XR_ConsoleMsg("XR_register failure for %s\n", key);
}
/* UGH: this ought to be more generally available ... */
char *
strdup(s)
char *s;
{
char *result = NIL;
if( s != NIL ) {
result = (char *) XR_malloc(1+strlen(s));
if( result != NIL ) (void)strcpy(result, s);
}
return result;
}
/*
* UGH: this smashes the string IN PLACE!!!
* I'm leaving it that way, because some client could conceviably
* depend on that (arrgh), but I'm also returning a COPY of the
* stripped string to avoid GC problems.
*/
char *
XR_strip(s)
char *s;
{
char *extrap, *extrap2, *result;
char *index(), *rindex();
/* start just after that last '/', if there is one. */
if ((extrap = rindex(s, '/')) == NIL)
extrap = s-1;
extrap += 1;
/* end just before the first '.' after the slash, if there is one. */
if ((extrap2 = index(extrap, '.')) != NIL)
*extrap2 = '\0';
result = (char *) XR_malloc(1+strlen(extrap));
(void) strcpy(result, extrap);
if( s ) return(result); /* make s live until after copy! */
}
#define WORD_BREAK " \t\n\r"
static char *
skip(s, span)
char *s, *span;
{
return s + strspn(s, span);
}
static char *
nskip(s, span)
char *s, *span;
{
return s + strcspn(s, span);
}
char *
get_nth_word(s, n)
char *s;
int n;
{
int len;
char *retval;
s = skip(s, WORD_BREAK);
for (; n > 0; n--) {
s = nskip(s, WORD_BREAK);
s = skip(s, WORD_BREAK);
}
len = strcspn(s, WORD_BREAK);
retval = (char *)calloc(len+1,1);
strncat(retval, s, len);
return retval;
}
static int _NEVERCALLED()
{
XR_Panic("_NEVERCALLED was called!");
strncmp();
}
XR_Pointer
XR_GetFrameBuffer( index )
int index;
{
XR_ConsoleMsg("%? GetFrameBuffer(%d) is OBSOLETE. Returning NIL.\n",
index );
return NIL;
}